Untitled3
pip install py3dmol --force-reinstall
import braketlab as bk
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
np.array(k3d.basic_color_maps.BlackBodyRadiation, dtype=np.float32)
array([0. , 0. , 0. , 0. , 0.4 , 0.9019608,
0. , 0. , 0.8 , 0.9019608, 0.9019608, 0. ,
1. , 1. , 1. , 1. ], dtype=float32)
#bk.braketlab.basisbank.hy.hydrogen_radial(1,0,1)
for n in range(1,5):
print(n)
display(bk.braketlab.basisbank.hy.hydrogen_radial(n,0,1).expand())
1
\(\displaystyle 2.0 e^{- r}\)
2
\(\displaystyle - 0.176776695296637 r e^{- 0.5 r} + 0.353553390593274 e^{- 0.5 r}\)
3
\(\displaystyle 0.00475185406740433 r^{2} e^{- \frac{r}{3}} - 0.0427666866066389 r e^{- \frac{r}{3}} + 0.0641500299099584 e^{- \frac{r}{3}}\)
4
\(\displaystyle - 5.42534722222222 \cdot 10^{-5} r^{3} e^{- \frac{r}{4}} + 0.00130208333333333 r^{2} e^{- \frac{r}{4}} - 0.0078125 r e^{- \frac{r}{4}} + 0.0104166666666667 e^{- \frac{r}{4}}\)
bk.braketlab.basisbank.hy.hydrogen_function(2,0,0)
\(\displaystyle \frac{0.0883883476483184 \left(2.0 \sqrt{x^{2} + y^{2} + z^{2}} e^{- 1.0 \sqrt{x^{2} + y^{2} + z^{2}}} - 1.0 \left(x^{2} + y^{2} + z^{2}\right) e^{- 1.0 \sqrt{x^{2} + y^{2} + z^{2}}}\right) e^{0.5 \sqrt{x^{2} + y^{2} + z^{2}}}}{\sqrt{\pi} \sqrt{x^{2} + y^{2} + z^{2}}}\)
import k3d
import SimpleITK as sitk
psi = bk.basisbank.get_hydrogen_function(5,2,2)
#psi = bk.basisbank.get_gto(4,2,0)
t = np.linspace(-1,1,100)*80
img = psi(t[None,None,:], t[None,:,None], t[:,None,None])
colormap = interp1d(np.linspace(0,1,Nc), np.random.uniform(0,1,(3, Nc)))
#embryo = k3d.volume(img.astype(np.float32),
# color_map=np.array(k3d.basic_color_maps.BlackBodyRadiation, dtype=np.float32),
# opacity_function = np.linspace(0,1,30)[::-1]**.1)
embryo1 = k3d.volume(img.astype(np.float32),
color_map=np.array(k3d.basic_color_maps.Gold, dtype=np.float32),
opacity_function = np.linspace(0,1,30)[::-1]**.2)
embryo2 = k3d.volume(-1*img.astype(np.float32),
color_map=np.array(k3d.basic_color_maps.Blues, dtype=np.float32),
opacity_function = np.linspace(0,1,30)[::-1]**.2)
plot = k3d.plot()
plot += embryo1
plot += embryo2
plot.display()
/opt/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:14: ComplexWarning: Casting complex values to real discards the imaginary part
/opt/anaconda3/lib/python3.7/site-packages/traittypes/traittypes.py:101: UserWarning: Given trait value dtype "float64" does not match required type "float32". A coerced copy has been created.
np.dtype(self.dtype).name))
/opt/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:18: ComplexWarning: Casting complex values to real discards the imaginary part
Output()
bk.show(psi)
Nx = 60
t = np.linspace(-10,10,Nx)
cubic = psi(t[:,None,None], t[None,:,None], t[None,None,:])
cubic.min()
import py3Dmol
cube, cm, cmax, cmin = bk.get_cubefile(psi)
v = py3Dmol.view()
#cm = cube.mean()
offs = cmax*.05
bins = np.linspace(cm-offs,cm+offs, 2)
#for i in range(len(bins)):
#di = int((255*i/len(bins)))
#v.addVolumetricData(cube, "cube", {'transferfn': '[{ Color: "#0000ff", pos: -0.2 },{ Color: "#0000ff", pos: -0.005 },{ Color: "#ff0000", pos: 0.005 },{ Color: "#ff0000", pos: 0.2 }]',
# 'opacityfn': '[{ opacity: 1.0, pos: -0.2 },{ opacity: 0, pos: -0.005 }, { opacity: 0, pos: 0.005 }, { opacity: 1.0, pos: 0.2 }, ]',
# 'coords': '[{x: 0, y: 0, z: 0}]',
# 'seldist': 1.7})
v.addVolumetricData(cube, "cube", {'transferfn': """[{color: "blue", opacity: .075, value: 0.1},{color: "blue", opacity: .001, value: 0.01}, {color: "white", opacity: 0, value: 0},{color: "red", opacity: .001, value: -0.01}, {color: "red", opacity: .075, value: -0.1}]"""})
v.zoomTo()
v.show()
v = py3Dmol.view()
v.GLVolumetricRender(cube)
v.view()
v.test_()
v.addVolumetricRenderer(cube, {
transferfn:[
{ Color: "#0000ff", pos: -0.2 },
{ Color: "#0000ff", pos: -0.005 },
{ Color: "#ff0000", pos: 0.005 },
{ Color: "#ff0000", pos: 0.2 },
],
opacityfn:[
{ opacity: 1.0, pos: -0.2 },
{ opacity: 0, pos: -0.005 },
{ opacity: 0, pos: 0.005 },
{ opacity: 1.0, pos: 0.2 },
],
coords: [{x: 0, y: 0, z: 0}],
seldist: 1.7
});
v = py3Dmol.view()
cube, cm, cmax, cmin = bk.get_cubefile(psi*.1)
#v.addVolumetricData(cube, "cube",{'negativeVolumetricColor':'#%02x%02x%02x' % (100,30,30), 'positiveVolumetricColor':'#%02x%02x%02x' % (100,30,30), 'opacity':.8})
#v.addVolumetricData(cube, "cube", {'isoval': 0.01, 'color': "red", 'opacity': 1.0})
#v.addVolumetricData(cube, "cube", {'isoval': 0.000005, 'color': "red", 'opacity': 1.0, 'alpha':.1})
#v.addVolumetricRender(cube, "cube", {'opacityfn':[[0,0,0], [.1,.1,.1]]})
v.addVolumetricData(cube, "cube", {'transferfn': """[{color: "blue", opacity: .075, value: 0.1},{color: "blue", opacity: .001, value: 0.01}, {color: "white", opacity: 0, value: 0},{color: "red", opacity: .001, value: -0.01}, {color: "red", opacity: .075, value: -0.1}]"""})
v.zoomTo();
v.render();
v.view()
help(v.addVolumetricRender)
py3Dmol.VolumeData
from IPython.display import *
def run_next_cells(n):
if n=='all':
n = 'NaN'
elif n<1:
return
js_code = """
var num = {0};
var run = false;
var current = $(this)[0];
$.each(IPython.notebook.get_cells(), function (idx, cell) {{
if ((cell.output_area === current) && !run) {{
run = true;
}} else if ((cell.cell_type == 'code') && !(num < 1) && run) {{
cell.execute();
num = num - 1;
}}
}});
""".format(n)
display(Javascript(js_code))
run_next_cells(2)
print("test2")
psi = bk.basisbank.get_hydrogen_function(4,3,2)
bk.show(psi)
You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
jupyter labextension install jupyterlab_3dmol
plt.figure()
Pt = psi(t[None,:],15.5, t[:, None])
P = np.conjugate(Pt)*Pt
plt.imshow(P.real)
plt.show()

P
array([[8.83572882e-34+0.j, 1.49825518e-33+0.j, 2.52553089e-33+0.j, ...,
2.52553089e-33+0.j, 1.49825518e-33+0.j, 8.83572882e-34+0.j],
[1.49825518e-33+0.j, 2.55328662e-33+0.j, 4.32568487e-33+0.j, ...,
4.32568487e-33+0.j, 2.55328662e-33+0.j, 1.49825518e-33+0.j],
[2.52553089e-33+0.j, 4.32568487e-33+0.j, 7.36576868e-33+0.j, ...,
7.36576868e-33+0.j, 4.32568487e-33+0.j, 2.52553089e-33+0.j],
...,
[2.52553089e-33+0.j, 4.32568487e-33+0.j, 7.36576868e-33+0.j, ...,
7.36576868e-33+0.j, 4.32568487e-33+0.j, 2.52553089e-33+0.j],
[1.49825518e-33+0.j, 2.55328662e-33+0.j, 4.32568487e-33+0.j, ...,
4.32568487e-33+0.j, 2.55328662e-33+0.j, 1.49825518e-33+0.j],
[8.83572882e-34+0.j, 1.49825518e-33+0.j, 2.52553089e-33+0.j, ...,
2.52553089e-33+0.j, 1.49825518e-33+0.j, 8.83572882e-34+0.j]])
146000*1.25
182500.0